<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body, html {
            height: 100%;
            background: url('../../assets/images/haokan.jpeg') no-repeat center center fixed;
            background-size: cover;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        }

        /* 添加一个遮罩层 */


        .container {
            position: relative; /* 确保内容在遮罩层上方 */
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .login-form {
            background: white;
            padding: 32px;
            border-radius: 12px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            width: 360px;
        }

        .login-title {
            text-align: center;
            margin-bottom: 8px;
            color: #000;
            font-size: 24px;
            font-weight: 500;
        }

        .login-subtitle {
            text-align: center;
            color: #666;
            font-size: 14px;
            margin-bottom: 32px;  /* 增加了底部间距 */
        }

        .form-group {
            margin-bottom: 16px;
        }

        .form-label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-size: 14px;
        }

        .form-input {
            width: 100%;
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 14px;
            transition: all 0.3s;
        }

        .form-input:focus {
            border-color: #000;
            outline: none;
        }

        .password-input-wrapper {
            position: relative;
        }

        .password-toggle {
            position: absolute;
            right: 12px;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            color: #999;
        }

        .btn-login {
            width: 100%;
            padding: 12px;
            background: linear-gradient(45deg, #4A90E2, #357ABD);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            cursor: pointer;
            margin-top: 8px;
            transition: all 0.3s ease;
        }

        .btn-login:hover {
            background: linear-gradient(45deg, #357ABD, #4A90E2);
            box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
        }

        .register-link {
            margin-top: 16px;
            text-align: center;
            font-size: 14px;
        }

        .register-link a {
            color: #4A90E2; /* 改为蓝色 */
            text-decoration: none;
            margin-left: 4px;
            font-weight: 500; /* 加粗 */
            transition: all 0.3s ease;
        }

        .register-link a:hover {
            color: #357ABD; /* hover时颜色加深 */
            text-decoration: none;
        }

        /* 移除layui的默认样式 */
        .layui-input:focus {
            border-color: #000 !important;
        }

        /* 在已有样式后添加 */
        .input-icon {
            position: absolute;
            left: 12px;
            top: 50%;
            transform: translateY(-50%);
            width: 16px;
            height: 16px;
            color: #999;
        }
        
        .form-input {
            padding-left: 36px !important; /* 为图标留出空间 */
        }
        
        .form-input-wrapper {
            position: relative;
        }

        /* 修改系统名称样式 */
        .system-name {
            text-align: center;
            margin-bottom: 4px;
            color: #4A90E2; /* 改为亮蓝色 */
            font-size: 20px;
            font-weight: 600; /* 加粗一点 */
            background: linear-gradient(45deg, #4A90E2, #357ABD);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            text-shadow: 0 1px 2px rgba(0,0,0,0.1);
        }

        .login-desc {
            text-align: center;
            color: #666;
            font-size: 14px;
            margin-bottom: 24px;
        }
    </style>
</head>
<body>
    <div class="container">
        <form class="login-form layui-form" lay-filter="loginForm">
            <div class="system-name">图书管理系统</div>
            <p class="login-desc">请登录以继续</p>
            
            <div class="form-group">
                <label class="form-label">用户名</label>
                <div class="form-input-wrapper">
                    <img src="../../assets/icons/user.svg" class="input-icon" alt="">
                    <input type="text" name="username" required lay-verify="required" 
                           placeholder="请输入用户名" autocomplete="off" 
                           class="form-input layui-input">
                </div>
            </div>

            <div class="form-group">
                <label class="form-label">密码</label>
                <div class="form-input-wrapper">
                    <img src="../../assets/icons/password.svg" class="input-icon" alt="">
                    <input type="password" name="password" required lay-verify="required" 
                           placeholder="请输入密码" autocomplete="off" 
                           class="form-input layui-input">
                    <span class="password-toggle">
                        <i class="layui-icon layui-icon-eyes"></i>
                    </span>
                </div>
            </div>

            <div class="login-options" style="display: none;">
                <div class="layui-form-item" pane="">
                    <div class="layui-input-block" style="margin-left: 0;">
                        <div v-for="(item,index) in menu" v-bind:key="index">
                            <input v-if="item.hasFrontLogin=='是'" type="radio" name="role" :value="item.tableName" :title="item.roleName">
                        </div>
                    </div>
                </div>
            </div>

            <button class="btn-login" lay-submit lay-filter="login">登录</button>
            
            <div class="register-link">
                <span>还没有账户？</span>
                <a v-if="item.hasFrontRegister=='是'" v-for="(item,index) in menu" v-bind:key="index" 
                   :href="'javascript:registerClick(\''+item.tableName+'\')'">注册</a>
            </div>
        </form>
    </div>

    <script src="../../layui/layui.js"></script>
    <script src="../../js/vue.js"></script>
    <script src="../../js/config.js"></script>
    <script src="../../modules/config.js"></script>
    <script src="../../js/utils.js"></script>
    <script>
        var vue = new Vue({
            el: '.container',
            data: {
                menu: menu
            },
            methods: {
                jump(url) {
                    jump(url)
                }
            }
        });

        layui.use(['layer', 'element', 'carousel', 'form', 'http', 'jquery'], function() {
            var layer = layui.layer;
            var element = layui.element;
            var carousel = layui.carousel;
            var form = layui.form;
            var http = layui.http;
            var jquery = layui.jquery;

            // 密码显示切换
            jquery('.password-toggle').click(function() {
                var input = jquery(this).siblings('input');
                var icon = jquery(this).find('i');
                if (input.attr('type') === 'password') {
                    input.attr('type', 'text');
                    icon.removeClass('layui-icon-eyes').addClass('layui-icon-eye');
                } else {
                    input.attr('type', 'password');
                    icon.removeClass('layui-icon-eye').addClass('layui-icon-eyes');
                }
            });

            // 登录
            form.on('submit(login)', function(data) {
                data = data.field;
                // 设置默认角色
                if (!data.role) {
                    data.role = 'yonghu'; // 设置默认用户类型
                }
                http.request(data.role + '/login', 'get', data, function(res) {
                    layer.msg('登录成功', {
                        time: 2000,
                        icon: 6
                    });
                    // 登录凭证
                    localStorage.setItem('Token', res.token);
                    localStorage.setItem('role', jquery('input[name="role"]:checked').attr('title') || '用户');
                    localStorage.setItem('tableName', data.role);
                    localStorage.setItem('sessionTable', data.role);
                    // 用户名称
                    localStorage.setItem('adminName', data.username);
                    http.request(data.role + '/session', 'get', {}, function(res) {
                        // 用户id
                        localStorage.setItem('userid', res.data.id);
                        // 路径访问设置
                        window.location.href = '../../index.html';
                    })
                });
                return false
            });
        });

        function registerClick(tablename) {
            window.location.href = '../' + tablename + '/register.html?tablename=' + tablename;
        }
    </script>
</body>
</html>
